<include file="public@header"/>
<style media="screen">
.aui_state_focus {
  z-index: 9999999999999!important;
}
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('delete_all')}" data-subcheck="true" data-msg="您确定删除吗？">
                {:lang('DELETE')}
            </button>
            <button class="btn btn-primary btn-sm" type="button" onclick="doAddAward('{:url('add')}')">添加奖品
            </button>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <notempty name="category">
                    <th width="50">{:lang('SORT')}</th>
                </notempty>
                <th width="280">奖品名称</th>
                <th width="140">奖品图片</th>
                <th width="50">所需积分</th>
                <th width="90">操作</th>
            </tr>
            </thead>
            <foreach name="list" item="vo">
                <tr>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}">
                    </td>
                    <td>{$vo.name}</td>
                    <td>{$vo.picture}</td>
                    <td>{$vo.score}</td>
                    <td>
                        <a href="{:url('edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a>
                        <a href="{:url('delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                    </td>
                </tr>
            </foreach>
            <tfoot>
            <tr>
                <th width="15"><label><input type="checkbox" class="js-check-all" data-direction="x"
                                             data-checklist="js-check-x"></label></th>
                <notempty name="category">
                    <th width="50">{:lang('SORT')}</th>
                </notempty>
                <th>奖品名称</th>
                <th>奖品图片</th>
                <th>所需积分</th>
                <th>操作</th>
            </tr>
            </tfoot>
        </table>
        <div class="table-actions">
            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('delete_all')}" data-subcheck="true" data-msg="您确定删除吗？">
                {:lang('DELETE')}
            </button>
        </div>
        <ul class="pagination">{$list->render()|default=''}</ul>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
function doAddAward(url) {
  openIframeLayer(url, '添加奖品', {
      area: ['500px', '400px'],
      btn: ['确定', '取消'],
      yes: function (index, layero) {
          //do something

          var iframeWin = window[layero.find('iframe')[0]['name']];
          var data = iframeWin.getForm();
          addForm(data.url, data.formData);

          layer.close(index); //如果设定了yes回调，需进行手工关闭
      }
  });
};


function addForm (url, formData) {
  $.post(url, formData, function (data) {
    var _refresh = function() {
        if (data.url) {
            //返回带跳转地址
            window.location.href = data.url;
        } else {
            if (data.code == 1) {
                //刷新当前页
                reloadPage(window);
            }
        }
    }

    function _refresh() {
        if (data.url) {
            //返回带跳转地址
            window.location.href = data.url;
        } else {
            if (data.code == 1) {
                //刷新当前页
                reloadPage(window);
            }
        }
    }

    if (data.code == 1) {
        noty({
            text: data.msg,
            type: 'success',
            layout: 'topCenter',
            modal: true,
            // animation: {
            //     open: 'animated bounceInDown', // Animate.css class names
            //     close: 'animated bounceOutUp', // Animate.css class names
            // },
            timeout: 800,
            callback: {
                afterClose: function () {
                  _refresh();
                }
            }
        }).show();
        $(window).focus();
    } else if (data.code == 0) {
        noty({
            text: data.msg,
            type: 'error',
            layout: 'topCenter',
            modal: true,
            // animation: {
            //     open: 'animated bounceInDown', // Animate.css class names
            //     close: 'animated bounceOutUp', // Animate.css class names
            // },
            timeout: 800,
            callback: {
                afterClose: function () {
                    _refresh();
                }
            }
        }).show();
        $(window).focus();
    }
  })
};
</script>
</body>
</html>
